<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <title>新增页面</title>
  <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
  <link rel="stylesheet" href="/app/admin/component/jsoneditor/css/jsoneditor.css" />
  <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
  <style>
    .layui-form-mid{
      margin-left: 110px;
    }
  </style>
</head>
<body>

<form class="layui-form" action="">
  <input type="hidden" name="id" value="<?=$id?>">

  <div class="mainBox">
    <div class="main-container mr-5">

      <div class="layui-form-item compact">
        <label class="layui-form-label">商户号mch_id</label>
        <div class="layui-input-block">
          <input type="text" name="mch_id" lay-verify="required" value="<?=$config['mch_id']?>" placeholder="商户号，服务商模式下为服务商商户号" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">商户号-可在 https://pay.weixin.qq.com/ 账户中心->商户信息 查看</div>
      </div>
      <div class="layui-form-item compact">
        <label class="layui-form-label">v2商户私钥</label>
        <div class="layui-input-block">
          <input type="text" name="mch_secret_key_v2" value="<?=$config['mch_secret_key_v2']?>" placeholder="选填-v2商户私钥" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">账户中心->API安全 中设置</div>
      </div>

      <div class="layui-form-item compact">
        <label class="layui-form-label">v3密钥</label>
        <div class="layui-input-block">
          <input type="text" name="mch_secret_key" lay-verify="required" value="<?=$config['mch_secret_key']?>" placeholder="必填-v3 商户秘钥" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"> 即 API v3 密钥(32字节，形如md5值)，可在 账户中心->API安全 中设置</div>
      </div>

      <div class="layui-form-item compact">
        <label class="layui-form-label">商户私钥</label>
        <div class="layui-input-block">
          <input type="text" name="mch_secret_cert" lay-verify="required" value="<?=$config['mch_secret_cert']?>" placeholder="必填-商户私钥 字符串或路径" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">即 API证书 PRIVATE KEY，可在 账户中心->API安全->申请API证书 里获得 文件名形如：apiclient_key.pem</div>
      </div>

      <div class="layui-form-item compact">
        <label class="layui-form-label">商户公钥</label>
        <div class="layui-input-block">
          <input type="text" name="mch_public_cert_path" lay-verify="required" value="<?=$config['mch_public_cert_path']?>" placeholder="必填-商户公钥证书路径" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">即 API证书 CERTIFICATE，可在 账户中心->API安全->申请API证书 里获得 文件名形如：apiclient_cert.pem</div>
      </div>


      <div class="layui-form-item compact">
        <label class="layui-form-label">异步回调</label>
        <div class="layui-input-block">
          <input type="text" name="notify_url" lay-verify="required" value="<?=$config['notify_url']?>" placeholder="必填-微信回调url" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">不能有参数，如?号，空格等，否则会无法正确回调</div>
      </div>

    </div>
  </div>

  <div class="bottom">
    <div class="button-container">
      <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
              lay-filter="save">
        提交
      </button>
      <button type="reset" class="pear-btn pear-btn-md">
        重置
      </button>
    </div>
  </div>

</form>

<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
<script src="/app/admin/component/pear/pear.js"></script>
<script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
<script src="/app/admin/admin/js/permission.js"></script>

<script>

  // 相关接口
  const INSERT_API = "/app/tuPay/tupay-config/setConfig";


  //提交事件
  layui.use(["form", "popup"], function () {
    // 字段验证允许为空
    layui.form.verify({
      phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
      email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
      url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
      number: [/(^$)|^\d+$/,'只能填写数字'],
      date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
      identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
    });
    layui.form.on("submit(save)", function (data) {
      layui.$.ajax({
        url: INSERT_API,
        type: "POST",
        dateType: "json",
        data: data.field,
        success: function (res) {
          if (res.code) {
            return layui.popup.failure(res.msg);
          }
          return layui.popup.success("操作成功", function () {
            parent.refreshTable();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
          });
        }
      });
      return false;
    });
  });

</script>

</body>
</html>
